package com.lcifn.spring.aop.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;

@Component
@Aspect
//@Order(1)
public class AspectJAnnotationBrowserAroundAdvice implements Ordered{
	@Pointcut("execution(* com.lcifn.spring.aop.bean.ChromeBrowser.*(..))")
	private void pointcut(){
		
	}
	
	//@Around(value="pointcut()")
	@Around("execution(* com.lcifn.spring.aop.bean.ChromeBrowser.*(..))")
	public Object aroundIntercept(ProceedingJoinPoint pjp) throws Throwable{
		//encrypt();
		System.out.println("around before 2");
		Object retVal = pjp.proceed();
		System.out.println("around after 2");
		//decrypt();
		return retVal;
	}
	
	@Before("pointcut()")
	public void before(){
		System.out.println("before 2");
	}
	
	@After("pointcut()")
	public void after(){
		System.out.println("after 2");
	}
	
	@AfterReturning("pointcut()")
	public void afterReturning(){
		System.out.println("after returning 2");
	}
	
	@AfterThrowing(value="pointcut()",throwing="ex")
	public void afterThrowing(Exception ex) throws Exception{
		System.out.println("afterThrowing 2");
		throw ex;
	}
	
	// 加密
	private void encrypt(){
		System.out.println("encrypt 2 ...");
	}
	
	// 解密
	private void decrypt(){
		System.out.println("decrypt 2 ...");
	}

	@Override
	public int getOrder() {
		// TODO Auto-generated method stub
		return 2;
	}
}
